package com.neu.servlet.ww;

import com.neu.service.ww.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "SearchKindServlet",urlPatterns = "/SearchKindServlet.do")
public class SearchKindServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String k_name=request.getParameter("k_name");
        k_name=new String(k_name.getBytes("ISO-8859-1"),"UTF-8");
        System.out.println(k_name);
        GoodsService goodsService=new GoodsService();
        List<Map<String,Object>> kindList=goodsService.doFindByKind(k_name);
        HttpSession session=request.getSession();
        if (kindList != null) {
            session.setAttribute("kindList", kindList);
            switch (k_name) {
                case "女装":
                    response.sendRedirect("/HAIGO/women.jsp");
                    break;
                case "男装":
                    response.sendRedirect("/HAIGO/men.jsp");
                    break;
                case "运动户外":
                    response.sendRedirect("/HAIGO/outside.jsp");
                    break;
                case "家居用品":
                    response.sendRedirect("/HAIGO/home.jsp");
                    break;
                case "医疗保健":
                    response.sendRedirect("/HAIGO/doctor.jsp");
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
